import 'package:enterprise_v6_app/app/components/common/no_permissions_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/drawer_title.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/user_manager.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_all_controller.dart';

/// 任务总页面
class TaskAllPage extends StatelessWidget {
  TaskAllPage({super.key});

  final controller = Get.put(TaskAllController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          // 没有登录时不执行操作
          if (!UserManager.isLoggedIn || controller.titleList.isEmpty) {
            return const NoPermissionsWidget();
          }
          return Scaffold(
            appBar: CustomAppBar(
              titleText: controller.titleList[controller.selectIndex].expandTitle,
              automaticallyImplyLeading: false,
            ),
            body: Scaffold(
              key: controller.scaffoldKey,
              drawer: Drawer(
                width: 200.w,
                child: Container(
                  color: Colors.white,
                  child: Column(
                    children: [
                      DrawerTitle.titleDrawer('收起', AppImages.icon_pack_up).click(() {
                        controller.scaffoldKey.currentState?.closeDrawer();
                      }),
                      Column(
                        children: controller.titleList.map((e) {
                          return DrawerTitle.titleDrawer(e.title, e.icon, isSelected: controller.selectIndex == controller.titleList.indexOf(e)).click(() {
                            controller.selectExpandMenu(controller.titleList.indexOf(e));
                          });
                        }).toList(),
                      ),
                    ],
                  ),
                ),
              ),
              body: Row(
                children: [
                  Container(
                    width: 60.w,
                    color: Colors.white,
                    alignment: Alignment.topCenter,
                    child: Column(
                      children: [
                        DrawerTitle.title('展开', AppImages.icon_launch).click(() {
                          controller.scaffoldKey.currentState?.openDrawer();
                        }),
                        Expanded(
                          child: SingleChildScrollView(
                              child: Column(
                            children: controller.titleList.map((e) {
                              return DrawerTitle.title(e.title, e.icon, isSelected: controller.selectIndex == controller.titleList.indexOf(e)).click(() {
                                controller.selectLeftMenu(controller.titleList.indexOf(e));
                              });
                            }).toList()
                              ..add(AppGaps.vGap10),
                          )),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Container(
                      color: const Color(0xffF5F5F6),
                      child: controller.titleList[controller.selectIndex].pages[controller.titleList[controller.selectIndex].currentPageTitle],
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }
}
